package com.podmanager.search;
import java.util.List;
import com.podmanager.UI.*;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class SearchArrayAdapter extends ArrayAdapter<SearchRecord> {

	private List<SearchRecord> mList=null;
	private ImageLoader imageLoader=null;

	public SearchArrayAdapter(Context context,
			int itemLayoutResourceId, List<SearchRecord> objects) {
		super(context, itemLayoutResourceId, objects);
		this.mList = objects;
		imageLoader=new ImageLoader(context);
	}

    public int getCount() {

        return this.mList.size();

    }

 

    public SearchRecord getItem(int index) {

        return this.mList.get(index);

    }
 
    public View getView(int position, View convertView, ViewGroup parent) {
        View row = convertView;
        if (row == null) {
            // ROW INFLATION
            Log.d("searcharrayadapter", "Starting XML Row Inflation ... ");
            LayoutInflater inflater = (LayoutInflater) this.getContext()
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            row = inflater.inflate(R.layout.add_search_item_layout, parent, false);
            Log.d("searcharrayadapter", "Successfully completed XML Row Inflation!");
        }
 
        // Get item
        SearchRecord searchRecord = getItem(position);
         
        ImageView podcastIcon=null;
        podcastIcon = (ImageView) row.findViewById(R.id.add_search_item_image);
        TextView searchTitle = (TextView) row.findViewById(R.id.add_search_item_title);
        TextView searchDescription = (TextView) row.findViewById(R.id.add_search_item_description);
        TextView searchUrl = (TextView) row.findViewById(R.id.add_search_item_URL);
  
        
        searchDescription.setText(searchRecord.getDescription());
        searchTitle.setText(searchRecord.getTitle());
        searchUrl.setText(searchRecord.getFeedUrl());
        
        try {
        	searchRecord.setImageView(podcastIcon);//set temporary image
            imageLoader.DisplayImage(searchRecord);//will parse rss feed and get actual image
        } catch (Exception e) {
            e.printStackTrace();
        }
         
        // Set country abbreviation
        
        return row;
    }
    


}
